home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / HotKeys / Test.c < prev   
Encoding:
C/C++ Source or Header  |  1993-11-29  |  1.8 KB  |  121 lines  |  [TEXT/KAHL]

  1. /*
  2.  *    File:        Test.c
  3.  *
  4.  *    Licensing:    This code may be used without fees provided that proper
  5.  *                copyright notice given.
  6.  *
  7.  *    History:    1.0.0    RSM        93-11-29    Created first version
  8.  *
  9.  *    ©1993 One Step Beyond
  10.  */
  11.  
  12. #ifdef THINK_C
  13. #    include <MacHeaders>
  14. #else
  15. #    include <Dialogs.h>
  16. #    include <Fonts.h>
  17. #    include <Memory.h>
  18. #    include <Menus.h>
  19. #    include <SegLoad.h>
  20. #endif
  21. #include "HotKeys.h"
  22.  
  23. enum{
  24.     iQuitBtn = 1,
  25.     iSetBtn,
  26.     iClearBtn,
  27.     iHotKeyDUI
  28. };
  29.  
  30.  
  31. void Inits( void );
  32. void GetDItemRect( DialogPtr, short, Rect* );
  33. void SetDUserItem( DialogPtr, short, void* );
  34. pascal void HotKeyDUI( DialogPtr, short );
  35.  
  36.  
  37. HotKey    gHotKey = {0,0,0,0};
  38.  
  39.  
  40. main()
  41. {
  42.     DialogPtr    dp;
  43.     short        hit;
  44.     
  45.     Inits();
  46.         
  47.     dp = GetNewDialog( 128, NULL, (GrafPtr)-1L );
  48.     SetPort( dp );
  49.     SetDUserItem( dp, iHotKeyDUI, &HotKeyDUI );
  50.  
  51.     do{
  52.         ModalDialog( NULL, &hit );
  53.         switch( hit ){
  54.             case iSetBtn:
  55.                 SetHotKeyDlog( &gHotKey );
  56.                 HotKeyDUI( dp, iHotKeyDUI );
  57.                 break;
  58.             case iClearBtn:
  59.                 ClearHotKey( &gHotKey );
  60.                 HotKeyDUI( dp, iHotKeyDUI );
  61.                 break;
  62.         }
  63.     }while( hit != iQuitBtn );
  64.     
  65.     DisposeDialog( dp );
  66.     ExitToShell();
  67. }
  68.  
  69.  
  70. pascal void 
  71. HotKeyDUI( DialogPtr dp, short item )
  72. {
  73.     Rect    bounds;
  74.     
  75.     GetDItemRect( dp, item, &bounds );
  76.  
  77.     // draw the frame
  78.     
  79.     PenNormal();
  80.     FrameRect( &bounds );
  81.     InsetRect( &bounds, 1, 1 );
  82.     EraseRect( &bounds );
  83.     DrawHotKey( &gHotKey, &bounds );    
  84. }
  85.  
  86.  
  87. void 
  88. Inits()
  89. {
  90.     MaxApplZone();
  91.     InitGraf( &qd.thePort );
  92.     InitFonts();
  93.     InitWindows();
  94.     InitMenus();
  95.     TEInit();
  96.     InitDialogs( NULL );
  97.     InitCursor();
  98. }
  99.  
  100.  
  101. void 
  102. SetDUserItem( DialogPtr dp, short itemID, void* duiProc )
  103. {
  104.     Handle    dumH;
  105.     short    dumSt;
  106.     Rect    dumR;
  107.     
  108.     GetDItem( dp, itemID, &dumSt, &dumH, &dumR );
  109.     SetDItem( dp, itemID, dumSt, duiProc, &dumR );
  110. }
  111.  
  112.  
  113. void 
  114. GetDItemRect( DialogPtr dp, short itemID, Rect *r )
  115. {
  116.     Handle    dumH;
  117.     short    dumSt;
  118.     
  119.     GetDItem( dp, itemID, &dumSt, &dumH, r );
  120. }
  121.